package com.aurora.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

/**
 * @author liu jun
 */

public class Hex2StrUtil {

    public static String hex2UTF8(String hexStr) throws UnsupportedEncodingException {
        return URLDecoder.decode(hexStr.replaceAll("\\\\x", "%"), StandardCharsets.UTF_8.name());
    }

    public static String hex2GBK(String hexStr) throws UnsupportedEncodingException, UnsupportedEncodingException {
        return URLDecoder.decode(hexStr.replaceAll("\\\\x", "%"), "gbk");
    }

    public static void main(String[] args) throws Exception {
        String utf8String = "\\xe9\\xa3\\x8e\\xe5\\xa5\\xb3\\xe9\\x83\\x8e";
        System.out.println(hex2UTF8(utf8String));
    }
}
